package com.lakeworks.service.api.impl;

import com.alibaba.fastjson2.JSONObject;
import com.lakeworks.common.domain.channel.*;
import com.lakeworks.common.domain.channel.ticket.TicketBeforeInfo;
import com.lakeworks.common.domain.channel.ticket.TicketChannel;
import com.lakeworks.common.domain.channel.ticket.TicketFileInfo;
import com.lakeworks.common.domain.channel.ticket.TicketSolveInfo;
import com.lakeworks.common.domain.ticket.TktClaimsRecord;
import com.lakeworks.common.utils.BaseApi;
import com.lakeworks.domain.CompleteInfo;
import com.lakeworks.domain.vo.TicketBackVo;
import com.lakeworks.service.api.MerchantApiService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Scope("prototype")
public class WaterFallApi extends BaseApi implements MerchantApiService {

    /**
     * 入场单状态回写
     */
    @Override
    public String backPickState(PickUpStatus pickUpStatus) {
        return getResult("/factory/lake/pickup/" + pickUpStatus.getPickupNo() + "/status", pickUpStatus);
    }

    /**
     * 回写产品信息
     */
    @Override
    public String backProduct(OprProductInfo productInfo) {
        return getResult("/factory/lake/pickup/" + productInfo.getPickupNo() + "/product/" + productInfo.getBarcode(), productInfo);
    }

    /**
     * 回写产品状态
     */
    @Override
    public String backProductState(ProductStatus productStatus) {
        return getResult("/factory/lake/pickup/" + productStatus.getPickupNo() + "/product/" + productStatus.getBarcode() + "/status", productStatus);
    }

    /**
     * 回写质检状态
     */
    @Override
    public String backQualState(QualityResult qualityResult) {
        return getResult("/factory/lake/pickup/" + qualityResult.getPickupNo() + "/product/" + qualityResult.getBarcode() + "/quality", qualityResult);
    }

    /**
     * 回写出厂单状态
     */
    @Override
    public String backShipState(ShipmentStatus shipmentStatus) {
        return getResult("/factory/lake/shipment/" + shipmentStatus.getShipmentNo() + "/status", shipmentStatus);
    }

    /**
     * 回写产品格架号
     */
    @Override
    public String backProductFrameNo(ProductFrame productFrame) {
        return getResult("/factory/lake/product/" + productFrame.getBarcode() + "/frameNo", productFrame);
    }


    @Override
    public String pushCompleteInfo(CompleteVo completeVo) {
        return getResult("/factory/lake/pickup/products/"+completeVo.getBarcode(),completeVo);
    }

    public Map<String, Object> pushTicket(TicketChannel ticketChannel) {
        return getTicketResult("/factory/ticket/create", ticketChannel);
    }

    @Override
    public Map ftyCansolveProcessor(TicketSolveInfo ticketSolveInfo) {
        System.out.println("可以处理");
        return getPatchResult("/factory/tickets/"+ticketSolveInfo.getTicketId()+"/ftyCansolveProcessor",ticketSolveInfo);
    }

    @Override
    public Map ftyHandledProcessor(TicketFileInfo ticketFileInfo) {
        System.out.println("已处理好");
        return getPatchResult("/factory/tickets/"+ticketFileInfo.getTicketId()+"/ftyHandledProcessor",ticketFileInfo);
    }

    @Override
    public Map ftyNohandledProcessor(TicketFileInfo ticketFileInfo) {
        System.out.println("处理不好");
        return getPatchResult("/factory/tickets/"+ticketFileInfo.getTicketId()+"/ftyNohandledProcessor",ticketFileInfo);
    }

    @Override
    public Map uploaddataProcessor(TicketFileInfo ticketFileInfo) {
        return getPatchResult("/factory/tickets/"+ticketFileInfo.getTicketId()+"/uploaddataProcessor",ticketFileInfo);
    }

    @Override
    public String isLeave(String orderNo) {
        return getGetResult("/factory/ticket/"+orderNo+"/supplement");
    }

    @Override
    public String getOrderInfo(String orderNo) {
        return getGetResult("/order/order/" + orderNo);
    }

    @Override
    public String getOrderDetails(String orderNo) {
        return getGetResult("/factory/lake/orders/" + orderNo + "/details");
    }

    @Override
    public String getOrderExpress(String expressNo) {
        return getGetResult("/factory/lake/express/" + expressNo + "/route");
    }

    public Map<String, Object> backTicket(TicketBackVo ticketBackVo) {
        return getTicketResult("/factory/ticket/feedback", ticketBackVo);
    }


    @Override
    public void initialize(JSONObject config,String AK,String SK) {
        String baseUrl = config.getString("baseurl");
        super.setBaseurl(baseUrl);
        super.AK = AK;
        super.SK = SK;
    }


    @Override
    public Map ftyFeedback(TicketFileInfo ticketFileInfo) {
        return getPatchResult("/factory/tickets/"+ticketFileInfo.getTicketId()+"/ftyFeedback",ticketFileInfo);
    }

    @Override
    public Map ftyHaveKnown(TicketFileInfo ticketFileInfo) {
        return getPatchResult("/factory/tickets/"+ticketFileInfo.getTicketId()+"/ftyHaveKnown",ticketFileInfo);
    }

    @Override
    public Map ftyBeforeWash(TicketBeforeInfo ticketBeforeInfo) {
        return getPatchResult("/factory/tickets/"+ticketBeforeInfo.getTicketId()+"/ftyBeforeWash",ticketBeforeInfo);
    }

    @Override
    public Map ftyInconsistency(TicketFileInfo ticketFileInfo) {
        return getPatchResult("/factory/tickets/"+ticketFileInfo.getTicketId()+"/ftyInconsistency",ticketFileInfo);
    }

    @Override
    public Map unbleToContact(TicketFileInfo ticketFileInfo) {
        return getPatchResult("/factory/tickets/"+ticketFileInfo.getTicketId()+"/unbleToContact",ticketFileInfo);
    }

    @Override
    public Map<String, Object> ticketUpdate(TicketFileInfo ticketFileInfo) {
        return getPatchResult("/factory/tickets/"+ticketFileInfo.getTicketId()+"/ticketUpdate",ticketFileInfo);
    }

    @Override
    public String reconsider(TktClaimsRecord tktClaimsRecord) {
        Map<String, Object> result = getPatchResult("/factory/claims/reconsider", tktClaimsRecord);
        return String.valueOf(result.get("code"));
    }



}
